﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;

public partial class yzadmin_data_diqu : YuuzleComic.Web.UI.ManagePage
{
    protected string json = "";
    YuuzleComic.BLL.diqu dqbll = new YuuzleComic.BLL.diqu();
    private JObject result = new JObject();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            switch (Request["a"])
            {
                case "list":
                    this.ProcessList();
                    break;
                case "save":
                    this.ProcessSave();
                    break;
                default:
                    break;
            }
        }
    }

    private void ProcessSave()
    {
        try
        {
            YuuzleComic.Model.ycdiqu diqu = new YuuzleComic.Model.ycdiqu();
            diqu.diqu = Request.Form["diqu"].Trim();
            diqu.filename = Request.Form["filename"].Trim();
            if (string.IsNullOrEmpty(Request.Form["id"]))
            {
                dqbll.Add(diqu);
            }
            else
            {
                diqu.id = Convert.ToInt32(Request.Form["id"]);
                dqbll.Update(diqu);
            }
            result.Add("success", true);
        }
        catch (Exception e)
        {
            result.Add("success", false);
            result.Add("errorMessage", e.Message);
        }
        finally
        {
            json = result.ToString();
        }
    }

    private void ProcessList()
    {
        try
        {
            JObject result = new JObject();
            DataSet ds = dqbll.GetAllList();
            result.Add("data", JArray.FromObject(ds.Tables[0]));
            result.Add("total", ds.Tables[0].Rows.Count);
            json = result.ToString();
        }
        catch (Exception)
        {

            throw;
        }
    }
}